//////////////////////////////////////////////////////////////////////////////
//
//  Detours Test Program (simple.cpp of simple.dll)
//
//  Microsoft Research Detours Package, Version 3.0.
//
//  Copyright (c) Microsoft Corporation.  All rights reserved.
//
//  This DLL will detour the Windows SleepEx API so that TimedSleep function
//  gets called instead.  TimedSleepEx records the before and after times, and
//  calls the real SleepEx API through the TrueSleepEx function pointer.
//
#include <stdio.h>
#include <windows.h>

#include "ProcessHelper/ProcessManager.h"

#define DLLEXPORT extern "C" __declspec(dllexport)

DLLEXPORT void SetMute( BOOL bMute );

DLLEXPORT void SetSpeed( double dbSpeed );

void GetSysVersion();
BOOL IsWin7OrLater();

BOOL g_b10014BEC = FALSE;
CProcessManager* pGameMgr = NULL;
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD dwReason, LPVOID reserved )
{
    ( void )hinst;
    ( void )reserved;

    if ( dwReason == DLL_PROCESS_ATTACH )
    {
        pGameMgr = CProcessManager::GetInstance();

        if ( g_b10014BEC )
        {
            GetSysVersion();
        }

//		CProcessManager::GetInstance()->HookSysFunc();
    }
    else if ( dwReason == DLL_PROCESS_DETACH )
    {
        if ( NULL != pGameMgr )
        {
            delete pGameMgr;
            pGameMgr = NULL;
        }
    }

    return TRUE;
}

void GetSysVersion()
{
    OSVERSIONINFO ovs;
    ovs.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
    GetVersionEx( &ovs );

    if ( ovs.dwMajorVersion >= 6 )
    {
        SYSTEM_INFO sio;
        GetNativeSystemInfo( &sio );

        if ( sio.wProcessorArchitecture != PROCESSOR_ARCHITECTURE_AMD64 || sio.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
        {

        }
    }
}

void SetMute( BOOL bMute )
{
    if ( IsWin7OrLater() )
    {
        pGameMgr->SetWin7Mute( bMute );
    }
    else
        pGameMgr->SetXpMute( bMute );
}

void SetSpeed( double dbSpeed )
{
    if ( IsWin7OrLater() )
    {
        pGameMgr->SetWin7Speed( dbSpeed );
    }
    else
        pGameMgr->SetXpSpeed( dbSpeed );
}

BOOL IsWin7OrLater()
{
    BOOL bIsWin7orLater = FALSE;
    OSVERSIONINFO osvi;
    ZeroMemory( &osvi, sizeof( OSVERSIONINFO ) );
    osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
    GetVersionEx( &osvi );
    bIsWin7orLater = ( ( osvi.dwMajorVersion > 6 ) || ( ( osvi.dwMajorVersion == 6 ) && ( osvi.dwMinorVersion >= 1 ) ) );
    return bIsWin7orLater;
}

//
///////////////////////////////////////////////////////////////// End of File.
